package hn.cch.apache.commons;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.junit.Test;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class CommonsTest {


    @Test
    public void testIOUtils() {
        FileInputStream fileInputStream = null;
        try {
            fileInputStream = new FileInputStream("");
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } finally {
            IOUtils.closeQuietly(fileInputStream);
        }

    }

    // 编码格式
    private static String encode = "utf-8";

    @Test
    public void testFileUtils() throws IOException {


        // File readFile = new File("E:\\temp\\updownload\\logo.png");
        // 读取文件得到字节数组或字符串
        // byte[] byteArray = FileUtils.readFileToByteArray(readFile);
        // String string = FileUtils.readFileToString(readFile, encode);
        //
        //
        // File writeFile = new File("C:\\Users\\lenovo\\Downloads\\logo.png");
        // // FileUtils.write(); 测试失败

        // 将字节数组或字符串写入文件
        // FileUtils.writeByteArrayToFile(writeFile, byteArray);
        //
        // writeFile.delete();
        // FileUtils.writeStringToFile(writeFile, string);
        // 删除文件
        FileUtils.deleteQuietly(new File("C:\\Users\\lenovo\\Downloads\\下载多文件压缩包\\logo.png"));
        // 删除文件夹
        FileUtils.deleteDirectory(new File("C:\\Users\\lenovo\\Downloads\\下载多文件压缩包\\"));


    }

}
